﻿<%@ WebHandler Language="C#" Class="GetDetailByPNumHandler" %>

using System;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Web.Script.Serialization;
using System.IO;
using System.Runtime.Serialization.Json;

public class GetDetailByPNumHandler : IHttpHandler
{

    public void ProcessRequest(HttpContext context)
    {


        string keyword = "";
        keyword = context.Request.QueryString["keyword"];
        PhoneReport model;
        List<PhoneReport> list = new List<PhoneReport>();


        string str = System.Configuration.ConfigurationManager.ConnectionStrings["decheatConnectionString"].ToString();
        string sql = "select * from PhoneView where object= '" + keyword + "'";
        SqlConnection conn = new SqlConnection(str);
        conn.Open();
        SqlCommand comm = new SqlCommand(sql, conn);
        System.Data.DataSet ds = new DataSet();
        SqlDataReader dr = comm.ExecuteReader();
        while (dr.Read())
        {

            bool Delete_flag = bool.Parse(dr["Delete_flag"].ToString());
            string brand = dr["brand"].ToString();
            string cardtype = dr["cardtype"].ToString();
            string city = dr["city"].ToString();
            int companyid = int.Parse(dr["companyid"].ToString());
            int id = int.Parse(dr["id"].ToString());
            string mode = dr["mode"].ToString();
            string num = dr["num"].ToString();
            string zoom = dr["zoom"].ToString();
            string e_company = dr["E_company"].ToString();
            string company = dr["company"].ToString();
            model = new PhoneReport(Delete_flag, brand, cardtype, city, companyid, id, mode, num, zoom, e_company, company);
            list.Add(model);
        }
        dr.Close();
        if (conn.State == ConnectionState.Open)
        {
            conn.Close();
        }
        //JavaScriptSerializer json = new JavaScriptSerializer();
        string result = WebUI.CommonClass.JSONHelper.Obj2Json<PhoneReport>(list[0]);
        context.Response.ContentType = "text/plain";
        context.Response.Write(result);
    }

    public bool IsReusable
    {
        get
        {
            return false;
        }
    }

}